package com.zxq.frame.modbus;

public enum EModBusFunCode {

    /**
     * 读线圈状态
     */
    READ_COLL_STATUS(0X01),
    /**
     * 读离散输入状态
     */
    READ_INPUT_STATUS(0X02),
    /**
     * 读保存寄存器
     */
    READ_HOLDING_REGISTER(0X03),
    /**
     *读输入寄存器
     */
    READ_INPUT_REGISTER(0X04),
    /**
     * 写线圈状态
     */
    WRITE_SINGLE_COLL(0x05),
    /**
     * 写单个保持寄存器
     */
    WRITE_SINGLE_REGISTER(0X06),
    /**
     * 写多个线圈
     */
    WRITE_MULTIPLE_COLL(0X15),
    /**
     * 写多个保持寄存器
     */
    WRITE_MULTIPLE_REGISTER(0X16),
    /**
     * 未知
     */
    UNKNOW(-1);

    Integer value;
    EModBusFunCode(Integer value) {
        this.value = value;
    }

    public static EModBusFunCode getType(Integer value) {
        EModBusFunCode eModBusFunCode = EModBusFunCode.UNKNOW;
        switch (value) {
            case 1:
                eModBusFunCode = READ_COLL_STATUS;
                break;
            case 2:
                eModBusFunCode = READ_INPUT_STATUS;
                break;
            case 3:
                eModBusFunCode = READ_HOLDING_REGISTER;
                break;
            case 4:
                eModBusFunCode = READ_INPUT_REGISTER;
                break;
            case 5:
                eModBusFunCode = WRITE_SINGLE_COLL;
                break;
            case 6:
                eModBusFunCode = WRITE_SINGLE_REGISTER;
                break;
            case 15:
                eModBusFunCode = WRITE_MULTIPLE_COLL;
                break;
            case 16:
                eModBusFunCode = WRITE_MULTIPLE_REGISTER;
                break;
        }
        return eModBusFunCode;
    }

}
